<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: Game</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.game</a> ]
    </div>

    <h1>Coverage Summary for Class: Game (nl.tudelft.jpacman.game)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">Game</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 7)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 24)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.game;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.util.List;
        <i>4</i>&nbsp;
        <i>5</i>&nbsp;import nl.tudelft.jpacman.board.Direction;
        <i>6</i>&nbsp;import nl.tudelft.jpacman.level.Level;
        <i>7</i>&nbsp;import nl.tudelft.jpacman.level.Level.LevelObserver;
        <i>8</i>&nbsp;import nl.tudelft.jpacman.level.Player;
        <i>9</i>&nbsp;import nl.tudelft.jpacman.points.PointCalculator;
        <i>10</i>&nbsp;
        <i>11</i>&nbsp;/**
        <i>12</i>&nbsp; * A basic implementation of a Pac-Man game.
        <i>13</i>&nbsp; *
        <i>14</i>&nbsp; * @author Jeroen Roosen
        <i>15</i>&nbsp; */
        <i>16</i>&nbsp;public abstract class Game implements LevelObserver {
        <i>17</i>&nbsp;
        <i>18</i>&nbsp; /**
        <i>19</i>&nbsp; * &lt;code&gt;true&lt;/code&gt; if the game is in progress.
        <i>20</i>&nbsp; */
        <i>21</i>&nbsp; private boolean inProgress;
        <i>22</i>&nbsp;
        <i>23</i>&nbsp; /**
        <i>24</i>&nbsp; * Object that locks the start and stop methods.
        <i>25</i>&nbsp; */
        <b class="nc"><i>26</i>&nbsp; private final Object progressLock = new Object();</b>
        <i>27</i>&nbsp;
        <i>28</i>&nbsp; /**
        <i>29</i>&nbsp; * The algorithm used to calculate the points that
        <i>30</i>&nbsp; * they player gets whenever some action happens.
        <i>31</i>&nbsp; */
        <i>32</i>&nbsp; private PointCalculator pointCalculator;
        <i>33</i>&nbsp;
        <i>34</i>&nbsp; /**
        <i>35</i>&nbsp; * Creates a new game.
        <i>36</i>&nbsp; *
        <i>37</i>&nbsp; * @param pointCalculator
        <i>38</i>&nbsp; * The way to calculate points upon collisions.
        <i>39</i>&nbsp; */
        <b class="nc"><i>40</i>&nbsp; protected Game(PointCalculator pointCalculator) {</b>
        <b class="nc"><i>41</i>&nbsp; this.pointCalculator = pointCalculator;</b>
        <b class="nc"><i>42</i>&nbsp; inProgress = false;</b>
        <i>43</i>&nbsp; }
        <i>44</i>&nbsp;
        <i>45</i>&nbsp; /**
        <i>46</i>&nbsp; * Starts or resumes the game.
        <i>47</i>&nbsp; */
        <i>48</i>&nbsp; public void start() {
        <b class="nc"><i>49</i>&nbsp; synchronized (progressLock) {</b>
        <b class="nc"><i>50</i>&nbsp; if (isInProgress()) {</b>
        <b class="nc"><i>51</i>&nbsp; return;</b>
        <i>52</i>&nbsp; }
        <b class="nc"><i>53</i>&nbsp; if (getLevel().isAnyPlayerAlive() &amp;&amp; getLevel().remainingPellets() &gt; 0)
            {</b>
        <b class="nc"><i>54</i>&nbsp; inProgress = true;</b>
        <b class="nc"><i>55</i>&nbsp; getLevel().addObserver(this);</b>
        <b class="nc"><i>56</i>&nbsp; getLevel().start();</b>
        <i>57</i>&nbsp; }
        <b class="nc"><i>58</i>&nbsp; }</b>
        <i>59</i>&nbsp; }
        <i>60</i>&nbsp;
        <i>61</i>&nbsp; /**
        <i>62</i>&nbsp; * Pauses the game.
        <i>63</i>&nbsp; */
        <i>64</i>&nbsp; public void stop() {
        <b class="nc"><i>65</i>&nbsp; synchronized (progressLock) {</b>
        <b class="nc"><i>66</i>&nbsp; if (!isInProgress()) {</b>
        <b class="nc"><i>67</i>&nbsp; return;</b>
        <i>68</i>&nbsp; }
        <b class="nc"><i>69</i>&nbsp; inProgress = false;</b>
        <b class="nc"><i>70</i>&nbsp; getLevel().stop();</b>
        <b class="nc"><i>71</i>&nbsp; }</b>
        <i>72</i>&nbsp; }
        <i>73</i>&nbsp;
        <i>74</i>&nbsp; /**
        <i>75</i>&nbsp; * @return &lt;code&gt;true&lt;/code&gt; iff the game is started and in progress.
        <i>76</i>&nbsp; */
        <i>77</i>&nbsp; public boolean isInProgress() {
        <b class="nc"><i>78</i>&nbsp; return inProgress;</b>
        <i>79</i>&nbsp; }
        <i>80</i>&nbsp;
        <i>81</i>&nbsp; /**
        <i>82</i>&nbsp; * @return An immutable list of the participants of this game.
        <i>83</i>&nbsp; */
        <i>84</i>&nbsp; public abstract List&lt;Player&gt; getPlayers();
        <i>85</i>&nbsp;
        <i>86</i>&nbsp; /**
        <i>87</i>&nbsp; * @return The level currently being played.
        <i>88</i>&nbsp; */
        <i>89</i>&nbsp; public abstract Level getLevel();
        <i>90</i>&nbsp;
        <i>91</i>&nbsp; /**
        <i>92</i>&nbsp; * Moves the specified player one square in the given direction.
        <i>93</i>&nbsp; *
        <i>94</i>&nbsp; * @param player
        <i>95</i>&nbsp; * The player to move.
        <i>96</i>&nbsp; * @param direction
        <i>97</i>&nbsp; * The direction to move in.
        <i>98</i>&nbsp; */
        <i>99</i>&nbsp; public void move(Player player, Direction direction) {
        <b class="nc"><i>100</i>&nbsp; if (isInProgress()) {</b>
        <i>101</i>&nbsp; // execute player move.
        <b class="nc"><i>102</i>&nbsp; getLevel().move(player, direction);</b>
        <b class="nc"><i>103</i>&nbsp; pointCalculator.pacmanMoved(player, direction);</b>
        <i>104</i>&nbsp; }
        <i>105</i>&nbsp; }
        <i>106</i>&nbsp;
        <i>107</i>&nbsp; @Override
        <i>108</i>&nbsp; public void levelWon() {
        <b class="nc"><i>109</i>&nbsp; stop();</b>
        <i>110</i>&nbsp; }
        <i>111</i>&nbsp;
        <i>112</i>&nbsp; @Override
        <i>113</i>&nbsp; public void levelLost() {
        <b class="nc"><i>114</i>&nbsp; stop();</b>
        <i>115</i>&nbsp; }
        <i>116</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
